package com.liruo.treasureattic.service.url.controller.impl;

import com.liruo.treasureattic.common.httpmsg.result.BaseResponse;
import com.liruo.treasureattic.common.model.dto.url.*;
import com.liruo.treasureattic.common.model.vo.url.UrlFolderVo;
import com.liruo.treasureattic.common.model.vo.url.UrlQueryVo;
import com.liruo.treasureattic.common.model.vo.url.UrlVo;
import com.liruo.treasureattic.common.util.ValidatorUtil;
import com.liruo.treasureattic.service.url.service.TreasureUrlService;
import com.liruo.treasureattic.service.url.service.UrlAndFolderService;
import com.liruo.treasureattic.service.url.service.UrlFolderService;
import com.liruo.treasureattic.service.url.controller.UrlController;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:liruo
 * @Date:2022-10-31-20:33:42
 * @Desc
 */
@RestController
public class UrlControllerImpl implements UrlController {
    @Resource
    private TreasureUrlService treasureUrlService;
    @Resource
    private UrlFolderService urlFolderService;
    @Resource
    private UrlAndFolderService urlAndFolderService;

    @Override
    public BaseResponse<Long> addUrl(UrlAddReq urlAddReq){
        ValidatorUtil.anyNull(urlAddReq);
        return BaseResponse.success(treasureUrlService.addUrl(urlAddReq));
    }
    @Override
    public BaseResponse<Boolean> updateUrl(UrlUpdateReq urlUpdateReq){
        ValidatorUtil.anyNull(urlUpdateReq);
        treasureUrlService.updateUrl(urlUpdateReq);
        return BaseResponse.success(true);
    }


    @Override
    public BaseResponse<Long>  addDefaultFolder(UrlFolderAddReq defaultFolderAddReq) {
        ValidatorUtil.anyNull(defaultFolderAddReq);
        return BaseResponse.success(urlFolderService.addDefaultFolder(defaultFolderAddReq));
    }
    @Override
    public BaseResponse<Long>  addFolder(UrlFolderAddReq folderAddReq) {
        ValidatorUtil.anyNull(folderAddReq);
        return BaseResponse.success(urlFolderService.addFolder(folderAddReq));
    }
    @Override
    public BaseResponse<Boolean> updateFolder(UrlFolderUpdateReq urlFolderUpdateReq) {
        ValidatorUtil.anyNull(urlFolderUpdateReq);
        urlFolderService.updateFolder(urlFolderUpdateReq);
        return BaseResponse.success(true);
    }

    @Override
    public BaseResponse<UrlQueryVo> queryOnce(UrlQueryOneLevelReq urlQueryOneLevelReq){
        ValidatorUtil.anyNull(urlQueryOneLevelReq);
        return BaseResponse.success(urlAndFolderService.queryOneLevel(urlQueryOneLevelReq));
    }
    @Override
    public BaseResponse<List<UrlVo>> queryUrlsByFid(Long fid){
        ValidatorUtil.requireGreat0(fid);
        return BaseResponse.success(treasureUrlService.getUrlByFid(fid));
    }
    @Override
    public BaseResponse<List<UrlFolderVo>> queryAllFolder(){
        return BaseResponse.success(urlFolderService.getAllFolder());
    }


    @Override
    public BaseResponse<List<UrlFolderVo>>  importUrlByHtml(HtmlUrlImportReq htmlUrlImportReq){
        ValidatorUtil.anyNull(htmlUrlImportReq);
        return BaseResponse.success(urlAndFolderService.importUrlByHtml(htmlUrlImportReq));
    }

    @Override
    public BaseResponse<Boolean> delUrl(Long urlId){
        ValidatorUtil.anyNull(urlId);
        treasureUrlService.delUrl(urlId);
        return BaseResponse.success(true);
    }
    @Override
    public BaseResponse<Boolean> delFolder(Long folderId) {
        ValidatorUtil.requireGreat0(folderId);
        urlAndFolderService.delFolder(folderId);
        return BaseResponse.success(true);
    }
}
